<template>
  <div id="updateGender">
    <van-picker
      title="性别修改"
      show-toolbar
      :columns="columns"
      :default-index="defaultGender"
      @confirm="onConfirm"
      @cancel="$emit('colose-gender')"
    />
  </div>
</template>
<script>
import { setUserInfo } from '@/api/user'
import { Toast } from 'vant'
export default {
  name: 'UpdateGender',
  data () {
    return {
      columns: ['女', '男'],
      defaultGender: this.value
    }
  },
  created () {},
  methods: {
    async onConfirm (value, index) {
      Toast.loading({
        message: '保存中...',
        forbidClick: true
      })
      try {
        await setUserInfo({
          gender: index
        })
        this.$emit('colose-gender')
        Toast.success('保存成功')
        this.$emit('input', index)
      } catch (error) {
        Toast.fail('修改失败')
        return error
      }
    }
  },
  components: {},
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  watch: {},
  computed: {},
  mounted () {}
}
</script>

<style lang="less" scoped></style>
